<%@page import="leagal_aid.util.PageUtil"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ page import="leagal_aid.bean.*,java.util.*,java.io.*" %>
<%
String username=null;
if(session.getAttribute("username")==null || session.getAttribute("username").equals("")){
	response.setCharacterEncoding("utf-8");
	PrintWriter pout = response.getWriter();
	pout.print("<script>alert('请先登录'); window.location='../login.jsp' </script>");
	pout.flush();
	pout.close();
}
else{
	username = session.getAttribute("username").toString();
}

	
	int everyPage = 10; //每页的记录条数
	int currentPage = 1;//当前的页码
	//接收页码
	if (request.getParameter("PageNo") != null) { //如果为空，则表示第1页
	currentPage = Integer.parseInt(request.getParameter("PageNo"));
	}
	MessageBean messageBean = new MessageBean();	
	int totalCount = messageBean.findbackCountByLb("message");
	//不设置查询条件
	Page leagalPage = PageUtil.createPage(everyPage, totalCount, currentPage); 
	List<MessageBean> list = new ArrayList<>(); 
	list = messageBean.findbackByLbForFY("message", leagalPage);
	

%>
<!DOCTYPE html>
<html class="x-admin-sm">
    <head>
        <meta charset="UTF-8">
        <title>在线留言</title>
        <meta name="renderer" content="webkit">
        <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
        <meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
        <link rel="stylesheet" href="../css/font.css">
        <link rel="stylesheet" href="../css/xadmin.css">
		<link rel="stylesheet" href="../css/page.css">
        <script src="../lib/layui/layui.js" charset="utf-8"></script>
        <script type="text/javascript" src="../js/xadmin.js"></script>
    </head>
    <body>
       <div class="layui-fluid">
            <div class="layui-row layui-col-space15">
                <div class="layui-col-md12">
                    <div class="layui-card">
                        <div class="layui-card-body layui-table-body layui-table-main"> 
                            <table class="layui-table layui-form">
                                <thead>
                                  <tr>
                                    <th style="text-align: center;">ID</th>
                                    <th style="text-align: center;">姓名</th>
                                    <th style="text-align: center;">手机号</th>
                                    <th style="text-align: center;">邮箱</th>
                                    <th style="text-align: center;">留言内容</th>
                                    <th style="text-align: center;">操作</th>
                                    </tr>
                                </thead>
                                <tbody>
                                 <% for(int i = 0; i <list.size();i++){%>
                                  <tr style="text-align: center;">
                                    <td><%=i + 1 %></td>
                                    <td><%= list.get(i).getName()%></td>
                                    <td><%= list.get(i).getTelephone()%></td>
                                    <td><%= list.get(i).getEmail()%></td> 
                                    <td style="max-width:50px; /*假设，5个字符的宽度是50*/
									white-space:nowrap; /*禁止换行*/
									text-overflow:ellipsis; /*文本超出隐藏*/
									-o-text-overflow:ellipsis;/*跟上面一样，只是为了兼容其他浏览器*/
									overflow: hidden; /*隐藏，跟text-overflow配合使用*/">
									<a href="message_information.jsp?id=<%=list.get(i).getId() %>"><%= list.get(i).getContent()%></a></td>
                                    <td class="td-manage">
                                      <a title="删除" onclick="member_del(this,'要删除的id')" href="operating_message/del_message.jsp?id=<%= list.get(i).getId()%>">
                                        <i class="layui-icon">&#xe640;</i>
                                      </a>
                                    </td>
                                  </tr>
                                  <% }%>
                                </tbody>
                            </table>
                         </div>
            			<div id="page" style="padding-bottom: 2%;">
    						<ul>
								<li class="xl-prevPage" onclick="window.location.href='message.jsp?PageNo=<%=leagalPage.getCurrentPage() - 1%>'">上一页</li>
								<li>1</li>
								<li class="xl-disabled">...</li>
								<li>17</li>
								<li>18</li>
								<li>19</li>
								<li class="xl-active">20</li>
								<li class="xl-nextPage xl-disabled" onclick="window.location.href='message.jsp?PageNo=<%=leagalPage.getCurrentPage() + 1%>'">下一页</li>
							</ul>
						</div>
                     </div>
                </div>
            </div>
        </div> 
    </body>
    <script src="https://www.jq22.com/jquery/jquery-1.10.2.js"></script>
<script type="text/javascript" src="../js/xlPaging.js"></script>
<script>
    // xlPaging.js 使用方法
    $("#page").paging({
        nowPage: <%=leagalPage.getCurrentPage()%>, // 当前页码
        pageNum: <%=leagalPage.getTotalPage()%>, // 总页码
        buttonNum: 7, //要展示的页码数量
       callback: function (num) { //回调函数
            console.log(num);
            window.location.href="message.jsp?PageNo="+num;
        } 
    });
</script>
   </html> 